<template>
    <a-spin :spinning="confirmLoading">
        <j-form-container :disabled="formDisabled">
            <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
                <a-row>
                    <a-col :span="6">
                        <a-form-model-item label="服务名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serverCode">
                            <a-input v-model="model.serverCode" placeholder="请输入服务名" disabled></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="6">
                        <a-form-model-item label="任务名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskCode">
                            <a-input v-model="model.taskCode" placeholder="请输入任务名" disabled></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="6">
                        <a-form-model-item label="发起系统" :labelCol="labelCol" :wrapperCol="wrapperCol"
                                           prop="sourceSystem">
                            <a-input v-model="model.sourceSystem" placeholder="请输入发起系统" disabled></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="6">
                        <a-form-model-item label="流水号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serialNo">
                            <a-input v-model="model.serialNo" placeholder="请输入流水号" disabled></a-input>
                        </a-form-model-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col :span="12">
                        <a-form-model-item label="请求数据" :labelCol="labelCol1" :wrapperCol="wrapperCol1"
                                           prop="requestText">
                            <a-textarea v-model="model.requestText" rows="4" placeholder="请输入请求数据文本"/>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="12">
                        <a-form-model-item label="响应数据" :labelCol="labelCol1" :wrapperCol="wrapperCol1"
                                           prop="responseText">
                            <a-textarea v-model="model.responseText" rows="4" placeholder="请输入响应数据文本"/>
                        </a-form-model-item>
                    </a-col>
                </a-row>
            </a-form-model>
        </j-form-container>
        <a-tabs v-model="activeKey">
            <a-tab-pane tab="记录明细" :key="refKeys[0]" :forceRender="true">
                <a-table
                        :ref="refKeys[0]"
                        size="small"
                        :scroll="{x:true}"
                        bordered
                        rowKey="id"
                        :columns="columns"
                        :dataSource="dataSource"
                        :pagination="ipagination"
                        :loading="loading"
                        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                        class="j-table-force-nowrap"
                        @change="handleTableChange"
                >
                    <template slot="ellipsisText" slot-scope="text">
                        <j-ellipsis :value="text" :length="30"></j-ellipsis>
                    </template>
                </a-table>
            </a-tab-pane>
        </a-tabs>
    </a-spin>
</template>

<script>

    import { getAction, httpAction } from '@/api/manage'
    import '@/assets/less/TableExpand.less'
    import { mixinDevice } from '@/utils/mixin'
    import { JeecgListMixinNone } from '@/mixins/JeecgListMixinNone'

    export default {
        name: 'MsiServerRecordForm',
        mixins: [JeecgListMixinNone, mixinDevice],
        components: {},
        props: {
            //表单禁用
            disabled: {
                type: Boolean,
                default: false,
                required: false
            }
        },
        data() {
            return {
                model: {},
                labelCol: {
                    xs: { span: 24 },
                    sm: { span: 5 },
                },
                wrapperCol: {
                    xs: { span: 24 },
                    sm: { span: 16 },
                },
                labelCol1: {
                    xs: { span: 24 },
                    sm: { span: 2 },
                },
                wrapperCol1: {
                    xs: { span: 24 },
                    sm: { span: 20 },
                },

                confirmLoading: false,
                validatorRules: {},
                url: {
                    list: '/msibase/msiServerRecord/getInfo',
                },
                refKeys: ['recordInfo',],
                activeKey: 'recordInfo',
                loading: false,
                dataSource: [],
                columns: [
                    {
                        title: '#',
                        dataIndex: '',
                        key: 'rowIndex',
                        width: 60,
                        align: 'center',
                        customRender: function (t, r, index) {
                            return parseInt(index) + 1
                        }
                    },
                    {
                        title: '节点',
                        align: 'center',
                        sorter: true,
                        dataIndex: 'node'
                    },
                    {
                        title: '节点名',
                        align: 'center',
                        dataIndex: 'nodeName'
                    },
                    {
                        title: '数据文本',
                        align: 'center',
                        dataIndex: 'dataText',
                        scopedSlots: { customRender: 'ellipsisText' }
                    },
                    {
                        title: 'message',
                        align: 'center',
                        dataIndex: 'message',
                        scopedSlots: { customRender: 'ellipsisText' }

                    },
                    {
                        title: '记录时间',
                        align: 'center',
                        dataIndex: 'createTime'
                    },

                ],
            }
        },
        computed: {
            formDisabled() {
                return this.disabled
            },
        },
        created() {
        },
        methods: {
            add() {
                this.edit()
            },
            edit(record) {
                this.model = Object.assign({}, record)
                this.visible = true
                this.queryParam.recordId = this.model.id
                this.loadData(1)
            },
            loadData(arg) {
                if (!this.url.list) {
                    this.$message.error('请设置url.list属性!')
                    return
                }
                //加载数据 若传入参数1则加载第一页的内容
                if (arg === 1) {
                    this.ipagination.current = 1
                }
                var params = this.getQueryParams()//查询条件
                this.loading = true
                getAction(this.url.list, params).then((res) => {
                    if (res.success) {
                        //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
                        this.dataSource = res.result.records || res.result
                        if (res.result.total) {
                            this.ipagination.total = res.result.total
                        } else {
                            this.ipagination.total = 0
                        }
                        //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
                    } else {
                        this.$message.warning(res.message)
                    }
                }).finally(() => {
                    this.loading = false
                })
            },
            submitForm() {
                const that = this
                // 触发表单验证
                this.$refs.form.validate(valid => {
                    if (valid) {
                        that.confirmLoading = true
                        let httpurl = ''
                        let method = ''
                        if (!this.model.id) {
                            httpurl += this.url.add
                            method = 'post'
                        } else {
                            httpurl += this.url.edit
                            method = 'put'
                        }
                        httpAction(httpurl, this.model, method).then((res) => {
                            if (res.success) {
                                that.$message.success(res.message)
                                that.$emit('ok')
                            } else {
                                that.$message.warning(res.message)
                            }
                        }).finally(() => {
                            that.confirmLoading = false
                        })
                    }

                })
            },
        }
    }
</script>
